package com.share.device.controller;

import com.share.common.core.web.controller.BaseController;
import com.share.common.core.web.domain.AjaxResult;
import com.share.common.core.web.page.TableDataInfo;
import com.share.device.domain.CabinetType;
import com.share.device.service.ICabinetTypeService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.List;

@Tag(name="柜机类型接口管理")
@RestController
@RequestMapping("/cabinetType")
public class CabinetTypeController extends BaseController {
    @Autowired
    private ICabinetTypeService cabinetTypeService;

    //查询所有
    @Operation(summary = "查询所有柜机类型")
    @GetMapping("cabinetTypeList")
    public AjaxResult list() {
        List<CabinetType> cabinetTypesList = cabinetTypeService.list();
        return AjaxResult.success(cabinetTypesList);
    }

    //删除
    @Operation(summary = "删除柜机类型")
    @DeleteMapping("/{id}")
    public AjaxResult delete(@PathVariable Long[] ids) {
        boolean is_Success = cabinetTypeService.removeBatchByIds(Arrays.asList(ids));
        return toAjax(is_Success);
    }

    //修改
    @Operation(summary = "修改柜机类型")
    @PutMapping
    public AjaxResult update(@RequestBody CabinetType cabinetType) {
        boolean is_Success = cabinetTypeService.updateById(cabinetType);
        return toAjax(is_Success);
    }

    //添加操作
    @Operation(summary = "添加柜机类型")
    @PostMapping
    public AjaxResult add(@RequestBody CabinetType cabinetType) {
        boolean is_Success = cabinetTypeService.save(cabinetType);
        return toAjax(is_Success);
    }

    //根绝id查询详情
    @Operation(summary = "根据id查询详情")
    @GetMapping("{id}")
    public AjaxResult getById(@PathVariable Long id) {
        CabinetType cabinetType = cabinetTypeService.getById(id);
        return AjaxResult.success(cabinetType);
    }

    //进行分页查询
    @Operation(summary = "柜机类型分页查询")
    @GetMapping("/list")
    public TableDataInfo list(CabinetType cabinetType) {
        //封装分页参数数据
        startPage();
        List<CabinetType> cabinetTypesList = cabinetTypeService.selectCabinetTypeList(cabinetType);
        return getDataTable(cabinetTypesList);
    }
}
